package org.game.msgBuilder;

import java.util.List;

import org.game.db.bean.Player;
import org.game.db.bean.Role;
import org.game.db.vo.DressVO;
import org.game.module.rolebo.RoleBO;
import org.game.protobuf.s2c.S2CItemMsg.DressInfo;
import org.game.protobuf.s2c.S2CRoleMsg;
import org.game.protobuf.s2c.S2CRoleMsg.RoleInfo;
import org.game.protobuf.s2c.S2CRoleMsg.RoleInfoList;
import org.game.protobuf.s2c.S2CShareMsg.ChangeType;
import org.game.util.ProtoUnit;

import com.sojoys.artifact.manager.MessageManager;

/**
 * @author : DengYing
 * @CreateDate : 2017年8月15日 下午4:21:17
 * @Description ：Please describe this document
 */
public class RoleMsgBuilder {
	
	public static RoleInfo createRoleInfo(ChangeType type,Role role){
		RoleInfo.Builder builder = RoleInfo.newBuilder();
		builder.setCt(type);
		builder.setId(Long.toString(role.getId()));
		builder.setCid(role.getCid());
		builder.setFavor(role.getFavor());
		builder.setMood(role.getMood());
		builder.setStatus(role.getStatus());
		builder.addAllUnlockGift(role.getUnlockGift());
		builder.addAllUnlockHobby(role.getUnlockHobby());
		builder.setFavorCriticalPoint(role.isCriticalPoint());
		// 装备的时装
		DressVO vo = role.getRoleProxy().getDressVO();
		builder.setDress(ItemMsgBuilder.createDressInfo(type, vo));
		builder.setRoomId(role.getRoleProxy().getRoomVO().getCid());
		return builder.build();
	}
	
	public static RoleInfoList createRoleInfoList(ChangeType type,List<Role> roles){
		RoleInfoList.Builder builder = RoleInfoList.newBuilder();
		for (Role role : roles) {
			builder.addRoles(createRoleInfo(type, role));
		}
		return builder.build();
	}
	
	public static void sendRoleMsg(Player player,ChangeType type,Role...roles){
		RoleInfoList.Builder builder = RoleInfoList.newBuilder();
		for (Role role : roles) {
			if (role==null) {
				continue;
			}
			builder.addRoles(createRoleInfo(type, role));
		}
		player.getPlayerProxy().sendMsg(MessageManager.me().create(RoleBO.getRoles, ProtoUnit.toByte(builder.build())));
	}

	/**
	 * 更新精灵心情值
	 */
	public static S2CRoleMsg.UpdateRoleMood createRoleMoodList(List<Role> roles){
		S2CRoleMsg.UpdateRoleMood.Builder builder = S2CRoleMsg.UpdateRoleMood.newBuilder();
		roles.forEach(role -> {
			S2CRoleMsg.RoleMoodInfo.Builder subBuilder = S2CRoleMsg.RoleMoodInfo.newBuilder();
			subBuilder.setRoleId(role.getId()+"")
					.setMood(role.getMood());
			builder.addInfos(subBuilder);
		});
		return builder.build();
	}


}
